package com.yxinsur.imc.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.yxinsur.imc.business.domain.ImcRepoSupplier;
import com.yxinsur.imc.business.enums.IsDeletedEnum;
import com.yxinsur.imc.business.form.RepoInsForm;
import com.yxinsur.imc.business.vo.RepoInsVo;
import com.yxinsur.imc.common.utils.DateUtils;
import com.yxinsur.imc.common.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxinsur.imc.business.mapper.ImcRepoInsMapper;
import com.yxinsur.imc.business.domain.ImcRepoIns;
import com.yxinsur.imc.business.service.IImcRepoInsService;

/**
 * 保险产品库(险种)Service业务层处理
 * 
 * @author imc
 * @date 2021-03-26
 */
@Service
public class ImcRepoInsServiceImpl extends ServiceImpl<ImcRepoInsMapper, ImcRepoIns> implements IImcRepoInsService
{
    private static final Logger logger = LoggerFactory.getLogger(ImcRepoInsServiceImpl.class);

    @Autowired
    private ImcRepoInsMapper imcRepoInsMapper;

    /**
     * 查询保险产品库(险种)列表
     * 
     * @param repoInsForm 保险产品库(险种)
     * @return 保险产品库(险种)
     */
    @Override
    public List<RepoInsVo> selectImcRepoInsList(RepoInsForm repoInsForm)
    {
        logger.info("保险产品库列表查询，条件：{}",repoInsForm.toString());
        return imcRepoInsMapper.selectImcRepoInsList(repoInsForm);
    }

    /**
     * 新增保险产品库(险种)
     * 
     * @param repoInsForm 保险产品库(险种)
     * @return 结果
     */
    @Override
    public int insertImcRepoIns(RepoInsForm repoInsForm)
    {
        logger.info("保险产品库列表新增操作：{}",repoInsForm.toString());
        ImcRepoIns repoIns = new ImcRepoIns();
        BeanUtils.copyProperties(repoInsForm,repoIns);
        repoIns.setCreateTime(DateUtils.getNowDate());
        repoIns.setCreateId(SecurityUtils.getUsername());
        repoIns.setIsDeleted(IsDeletedEnum.N.getCode());
        repoIns.setTenantId(SecurityUtils.getTenantId());
        return this.imcRepoInsMapper.insert(repoIns);
    }

    /**
     * 修改保险产品库(险种)
     * 
     * @param repoInsForm 保险产品库(险种)
     * @return 结果
     */
    @Override
    public int updateImcRepoIns(RepoInsForm repoInsForm)
    {
        logger.info("保险产品库更新操作：{}",repoInsForm.toString());
        ImcRepoIns repoIns = this.imcRepoInsMapper.selectById(repoInsForm.getId());
        BeanUtils.copyProperties(repoInsForm,repoIns);
        repoIns.setUpdateTime(DateUtils.getNowDate());
        repoIns.setUpdateId(SecurityUtils.getUsername());
        return this.imcRepoInsMapper.updateById(repoIns);
    }

    /**
     * 批量删除保险产品库(险种)
     * 
     * @param ids 需要删除的保险产品库(险种)ID
     * @return 结果
     */
    @Override
    public int deleteImcRepoInsByIds(Long[] ids)
    {
        logger.info("保险产品库删除操作：{}",ids);
        int count = 0;
        for(Long id:ids){
            ImcRepoIns repoIns = this.imcRepoInsMapper.selectById(id);
            repoIns.setIsDeleted(repoIns.getId().toString());
            repoIns.setUpdateId(SecurityUtils.getUsername());
            repoIns.setUpdateTime(DateUtils.getNowDate());
            count += this.imcRepoInsMapper.updateById(repoIns);
        }
        return count;
    }

}
